package com.wss.dao;

import com.wss.domain.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 权限dao接口
 */
@Repository
public interface PermissionDao {

    /**
     * 查询所有权限
     * @return
     */
    @Select("select * from permissions order by permissions.id")
    List<Permission> findAll();

    /**
     * 添加权限 后面的数据变量名应和bean类相同
     * @param permission
     * @return
     */
    @Insert("insert into permissions (pname,pdesc) values (#{pname},#{pdesc})")
    int addPermission(Permission permission);

    /**
     * 修改权限信息
     * @param permission
     * @return
     */
    @Update("update permissions set pname = #{pname},pdesc = #{pdesc} where id=#{id}")
    int updatePermission(Permission permission);

    /**
     * 删除前先检查权限是否有用户正在使用
     * @param p_id
     * @return
     */
    @Select("select count(*) from account where p_id=#{p_id}")
    int p_idCheck(int p_id);

    /**
     * 删除权限 后面的数据变量名应和bean类相同
     * @param p_id
     * @return
     */
    @Delete("delete permissions from permissions where id=#{p_id}")
    int deletePermission(int p_id);

}
